package com.yn.pet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.pet.bus.dao.PhoneWhitelistDao;
import com.yn.pet.bus.entity.PhoneWhitelist;
import com.yn.pet.service.PhoneWhitelistService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


/**
 * <p>
 * 电话白名单表 服务实现类
 * </p>
 *
 * @author xuquanjun
 * @since 2025-08-08
 */
@Service
public class PhoneWhitelistServiceImpl extends ServiceImpl<PhoneWhitelistDao, PhoneWhitelist> implements PhoneWhitelistService {

    /**
     * 根据手机号查询白名单数据
     * @param phoneNumber 手机号
     * @return 手机号对应的白名单数据
     */
    @Override
    public PhoneWhitelist getOneByPhone(String phoneNumber) {
        if(StringUtils.isBlank(phoneNumber)) return null;
        return this.getOne(new QueryWrapper<PhoneWhitelist>().eq("phone_number", phoneNumber).eq("data_status", 1));
    }

    /**
     * 根据设备ID查询白名单数据
     * @param deviceId 设备ID
     * @return List<PhoneWhitelist>
     */
    @Override
    public List<PhoneWhitelist> listByDeviceId(Long deviceId) {
        if(deviceId==null) return Collections.emptyList();
        return this.list(new QueryWrapper<PhoneWhitelist>().eq("device_id", deviceId).eq("data_status", 1));
    }
}
